package love.yuanmengrobot.springmvcdemo2.service.impl;


import love.yuanmengrobot.springmvcdemo2.mapper.UserMapper;
import love.yuanmengrobot.springmvcdemo2.pojo.Users;
import love.yuanmengrobot.springmvcdemo2.service.UserService;
import love.yuanmengrobot.springmvcdemo2.utils.DataGridView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.DigestUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements UserService {


//    @Autowired
    @Resource
    UserMapper userMapper;

    /**
     * 登录
     *
     * @param users
     */
    @Override
    public Users login(Users users) {
        //加密 进行比较
        String pwd = DigestUtils.md5DigestAsHex(users.getPaw().getBytes());
        users.setPaw(pwd);
        Users user = this.userMapper.login(users);
        return user;
    }

    @Override
    public DataGridView queryAllUser(Users users) {
        List<Users> list = this.userMapper.queryAllUser(users);
        return new DataGridView(list);
    }
}
